package com.eveinfo.display.setting;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.eveinfo.EveInfo;
import com.eveinfo.R;
import com.eveinfo.tools.EveInfoPreferences;

public class SettingViewView extends Activity {

	private final EveInfoPreferences preferences;

	public SettingViewView() {
		preferences = EveInfo.getPreferences();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.settingview);

		final CheckBox image32 = (CheckBox) findViewById(R.id.CBSettingViewAssetsImage32);
		final CheckBox image64 = (CheckBox) findViewById(R.id.CBSettingViewAssetsImage64);

		final int assetsImageSize = preferences.getAssetsImageSize();
		if (assetsImageSize == EveInfoPreferences.ASSETS_IMAGE_SIZE_32) {
			image32.setChecked(true);
		} else {
			image64.setChecked(true);
		}

		image32.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					preferences.setAssetsImageSize(EveInfoPreferences.ASSETS_IMAGE_SIZE_32);
					image64.setChecked(false);
				}
			}
		});

		image64.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					preferences.setAssetsImageSize(EveInfoPreferences.ASSETS_IMAGE_SIZE_64);
					image32.setChecked(false);
				}
			}
		});

		final CheckBox checkDB = (CheckBox) findViewById(R.id.CBSettingViewAssetsCheckDB);
		checkDB.setChecked(preferences.isCheckDatabases());
		checkDB.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				preferences.setCheckDatabases(isChecked);
			}
		});
		
	}
}